package com.xiao.server.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiao.common.dto.UserDto;
import com.xiao.dao.AdminMappe;
import com.xiao.pojo.Admin;
import com.xiao.server.AdminLoginServer;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminLoginServerImpl implements AdminLoginServer {
    @Autowired
    private AdminMappe adminMappe;

    @Override
    public UserDto login(UserDto userDto) {
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_ID", userDto.getUserId());
        queryWrapper.eq("password", userDto.getPassword());
        List<Admin> list = adminMappe.selectList(queryWrapper);
        if (list.size() != 0){
            BeanUtils.copyProperties(list.get(0), userDto);
            userDto.setPassword(" ");
            return userDto;
        }else {
            return null;
        }
    }
}

